package com.ruoyi.entity.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;

import java.util.List;
import java.util.Arrays;

import com.ruoyi.common.utils.StringUtils;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.entity.domain.Conver;
import com.ruoyi.entity.service.IConverService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 会话Controller
 *
 * @author Delamer
 * @date 2020-12-23
 */
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/entity/conver")
public class ConverController extends BaseController {

    private final IConverService converService;

    /**
     * 查询会话列表
     */
    @PreAuthorize("@ss.hasPermi('entity:conver:list')")
    @GetMapping("/list")
    public TableDataInfo list(Conver conver) {
        startPage();
        LambdaQueryWrapper<Conver> lqw = new LambdaQueryWrapper<Conver>();
        if (conver.getGroupId() != null) {
            lqw.eq(Conver::getGroupId, conver.getGroupId());
        }
        if (conver.getUserId() != null) {
            lqw.eq(Conver::getUserId, conver.getUserId());
        }
        if (StringUtils.isNotBlank(conver.getConverReq())) {
            lqw.eq(Conver::getConverReq, conver.getConverReq());
        }
        if (StringUtils.isNotBlank(conver.getConverResp())) {
            lqw.eq(Conver::getConverResp, conver.getConverResp());
        }
        if (conver.getConverChance() != null) {
            lqw.eq(Conver::getConverChance, conver.getConverChance());
        }
        if (conver.getConverStatus() != null) {
            lqw.eq(Conver::getConverStatus, conver.getConverStatus());
        }
        if (conver.getSort() != null) {
            lqw.eq(Conver::getSort, conver.getSort());
        }
        lqw.orderByAsc(Conver::getSort);
        List<Conver> list = converService.list(lqw);
        return getDataTable(list);
    }

    /**
     * 导出会话列表
     */
    @PreAuthorize("@ss.hasPermi('entity:conver:export')")
    @Log(title = "会话", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Conver conver) {
        LambdaQueryWrapper<Conver> lqw = new LambdaQueryWrapper<Conver>(conver);
        List<Conver> list = converService.list(lqw);
        ExcelUtil<Conver> util = new ExcelUtil<Conver>(Conver.class);
        return util.exportExcel(list, "conver");
    }

    /**
     * 获取会话详细信息
     */
    @PreAuthorize("@ss.hasPermi('entity:conver:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(converService.getById(id));
    }

    /**
     * 新增会话
     */
    @PreAuthorize("@ss.hasPermi('entity:conver:add')")
    @Log(title = "会话", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Conver conver) {
        return toAjax(converService.save(conver) ? 1 : 0);
    }

    /**
     * 修改会话
     */
    @PreAuthorize("@ss.hasPermi('entity:conver:edit')")
    @Log(title = "会话", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Conver conver) {
        return toAjax(converService.updateById(conver) ? 1 : 0);
    }

    /**
     * 删除会话
     */
    @PreAuthorize("@ss.hasPermi('entity:conver:remove')")
    @Log(title = "会话", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(converService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
    }
}
